from datetime import date
import re
from flask import Blueprint,request,jsonify
import json
from db import db1
from werkzeug.utils import redirect
bp_login=Blueprint('sflogin',__name__)

@bp_login.route('/login',methods=['POST'])
def login():
    if request.method==['POST']:
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        sql = "select nikename,password from user where nikename='%s' and password='%s'"%(data['nikename'],data['password'])
        res = db1.find(sql)
        if res:
            return jsonify({'code':200})
        else:
            return jsonify({'code':20010,'mes':'用户或密码错误'})


@bp_login.route('/sf_login')
def sf_login():
    token='sfseefese'
    uid=788
    nikename = request.args.get('nikename')
    url='localhost:8888/queren?username='+str(nikename)+'&uid='+str(uid)+'&token='+str(token)
    return jsonify({'code':200,'url':url})
    